#include "infraredspectrum.h"
#include "private/infraredspectrumprivatedefine.h"
#include "common/dataspecificationutils.h"
#include "common/binaryprocesshelper.h"
#include "common/xmldocument.h"
#include "private/spectrumdatafilecommondefine.h"
#include "common/xmlprocesshelper.h"
#include <QDebug>

namespace DataSpecificationGW
{
    class InfraredSpectrumPrivate
    {
    public:
        InfraredExtInformationPrivate m_stInfraredExtInformationPrivate;
        InfraredDataPrivate m_stInfraredDataPrivate;
    };

    InfraredSpectrum::InfraredSpectrum()
        : Spectrum(),
          m_pInfraredSpectrumPrivate(new InfraredSpectrumPrivate)
    {
        setSpectrumTypeCode(SPECTRUM_CODE_INFRARED);
    }

    InfraredSpectrum::~InfraredSpectrum()
    {
    }

    /************************************************
     * 函数名   : setDataSpecificationVersion
     * 输入参数 :
       const DataSpecificationVersion eDataSpecificationVersion: 数据规范版本号
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置数据规范版本号
     ************************************************/
    void InfraredSpectrum::setDataSpecificationVersion(const DataSpecificationVersion eDataSpecificationVersion)
    {
        Spectrum::setDataSpecificationVersion(eDataSpecificationVersion);
        if (V_4_1_0_2 == eDataSpecificationVersion)
        {
            m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.skipTemperatureWidthUpper();
            m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.skipTemperatureWidthLower();
        }
    }

    /************************************************
     * 函数名   : spectrumName
     * 输入参数 : NULL
     * 输出参数 : NULL
     * 返回值   : QString
     * 功能     : 图谱名称
     ************************************************/
    QString InfraredSpectrum::spectrumName() const
    {
        return STR_FILE_NODE_INFRARED;
    }

    /************************************************
     * 函数名   : setInfraredExtInformation
     * 输入参数 :
       const InfraredExtInformation& stInfraredExtInformation: 红外ExtInformation
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置红外ExtInformation
     ************************************************/
    void InfraredSpectrum::setInfraredExtInformation(const InfraredExtInformation& stInfraredExtInformation)
    {
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit = stInfraredExtInformation.eTemperatureUnit;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth = stInfraredExtInformation.iTempLatticeWidth;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight = stInfraredExtInformation.iTempLatticeHeight;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1 = stInfraredExtInformation.iVisibleLightLenL1;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2 = stInfraredExtInformation.iInfraredDataLenL2;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity = stInfraredExtInformation.fEmissivity;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance = stInfraredExtInformation.fMeasureDistance;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature = stInfraredExtInformation.fAtomTemperature;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity = stInfraredExtInformation.cRelativeHumidity;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature = stInfraredExtInformation.fReflectedTemperature;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper = stInfraredExtInformation.fTemperatureWidthUpper;
        m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower = stInfraredExtInformation.fTemperatureWidthLower;
    }

    /************************************************
     * 函数名   : setInfraredData
     * 输入参数 :
       const InfraredData& stInfraredData: 红外数据
     * 输出参数 : NULL
     * 返回值   : void
     * 功能     : 设置红外数据
     ************************************************/
    void InfraredSpectrum::setInfraredData(const InfraredData& stInfraredData)
    {
        m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData = stInfraredData.qbaInfraredTemperatureData;
        m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData = stInfraredData.qbaVisibleLightPhotoData;
        m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData = stInfraredData.qbaInfraredPhotoData;
    }

    /************************************************
     * 函数名   : getInfraredExtInformation
     * 输入参数 : NULL
     * 输出参数 :
       InfraredExtInformation& stInfraredExtInformation: 红外ExtInformation
     * 返回值   : void
     * 功能     : 获取红外ExtInformation
     ************************************************/
    void InfraredSpectrum::getInfraredExtInformation(InfraredExtInformation& stInfraredExtInformation)
    {
        stInfraredExtInformation.eTemperatureUnit = static_cast<TemperatureUnit>(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit);
        stInfraredExtInformation.iTempLatticeWidth = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth;
        stInfraredExtInformation.iTempLatticeHeight = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight;
        stInfraredExtInformation.iVisibleLightLenL1 = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1;
        stInfraredExtInformation.iInfraredDataLenL2 = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2;
        stInfraredExtInformation.fEmissivity = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity;
        stInfraredExtInformation.fMeasureDistance = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance;
        stInfraredExtInformation.fAtomTemperature = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature;
        stInfraredExtInformation.cRelativeHumidity = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity;
        stInfraredExtInformation.fReflectedTemperature = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature;
        stInfraredExtInformation.fTemperatureWidthUpper = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper;
        stInfraredExtInformation.fTemperatureWidthLower = m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower;
    }

    /************************************************
     * 函数名   : getInfraredData
     * 输入参数 : NULL
     * 输出参数 :
       InfraredData& stInfraredData: 红外数据
     * 返回值   : void
     * 功能     : 获取红外数据
     ************************************************/
    void InfraredSpectrum::getInfraredData(InfraredData& stInfraredData)
    {
        stInfraredData.qbaInfraredTemperatureData = m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData;
        stInfraredData.qbaVisibleLightPhotoData = m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData;
        stInfraredData.qbaInfraredPhotoData = m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData;
    }

    /************************************************
     * 函数名   : saveBinarySpectrumExtInfo
     * 输入参数 :
       QDataStream& out: 输出流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存二进制可扩展信息段
     ************************************************/
    bool InfraredSpectrum::saveBinarySpectrumExtInfo(QDataStream& out)
    {
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureUnit) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeWidth) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeHeight) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipVisibleLightLenL1) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipInfraredDataLenL2) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipEmissivity) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipMeasureDistance) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipAtomTemperature) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipRelativeHumidity) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipReflectedTemperature) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthUpper) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper;
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthLower) out << m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthLower;

        return true;
    }

    /************************************************
     * 函数名   : saveXMLSpectrumExtInfo
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
       QDomElement& element: dom元素
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存XML可扩展信息段
     ************************************************/
    bool InfraredSpectrum::saveXMLSpectrumExtInfo(XMLDocument& xmlDocumentObj, QDomElement& element)
    {
        xmlDocumentObj.beginElement(element);
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_EXTINFORMATION);

        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureUnit) xmlDocumentObj.setValue(TEXT_TEMPERATURE_UNIT, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeWidth) xmlDocumentObj.setValue(TEXT_TEMPERATURE_LATTICE_WIDTH, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeHeight) xmlDocumentObj.setValue(TEXT_TEMPERATURE_LATTICE_HEIGHT, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipVisibleLightLenL1) xmlDocumentObj.setValue(TEXT_VISIBLE_LIGHT_PHOTO_DATA_LENGTH_L1, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipInfraredDataLenL2) xmlDocumentObj.setValue(TEXT_INFRARED_PHOTO_DATA_LENGTH_L2, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipEmissivity) xmlDocumentObj.setValue(TEXT_EMISSIVITY, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity, 'f', 1));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipMeasureDistance) xmlDocumentObj.setValue(TEXT_MEASURE_DISTANCE, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance, 'f', 1));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipAtomTemperature) xmlDocumentObj.setValue(TEXT_ATMOSPHERIC_TEMPERATURE, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature, 'f', 1));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipRelativeHumidity) xmlDocumentObj.setValue(TEXT_RELATIVE_HUMIDITY, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipReflectedTemperature) xmlDocumentObj.setValue(TEXT_REFLECTED_TEMPERATURE, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature, 'f', 1));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthUpper) xmlDocumentObj.setValue(TEXT_TEMPERATURE_WIDTH_UPPER, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper, 'f', 1));
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthLower) xmlDocumentObj.setValue(TEXT_TEMPERATURE_WIDTH_LOWER, QString::number(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower, 'f', 1));

        return true;
    }

    /************************************************
     * 函数名   : saveJSONSpectrumExtInfo
     * 输入参数 :
       rapidjson::Document::AllocatorType& alloc:
       rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存JSON可扩展信息段
     ************************************************/
    bool InfraredSpectrum::saveJSONSpectrumExtInfo(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& jsonValue)
    {
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureUnit) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit, TEXT_TEMPERATURE_UNIT, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeWidth) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth, TEXT_TEMPERATURE_LATTICE_WIDTH, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeHeight) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight, TEXT_TEMPERATURE_LATTICE_HEIGHT, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipVisibleLightLenL1) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1, TEXT_VISIBLE_LIGHT_PHOTO_DATA_LENGTH_L1, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipInfraredDataLenL2) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2, TEXT_INFRARED_PHOTO_DATA_LENGTH_L2, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipEmissivity) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity, TEXT_EMISSIVITY, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipMeasureDistance) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance, TEXT_MEASURE_DISTANCE, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipAtomTemperature) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature, TEXT_ATMOSPHERIC_TEMPERATURE, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipRelativeHumidity) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity, TEXT_RELATIVE_HUMIDITY, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipReflectedTemperature) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature, TEXT_REFLECTED_TEMPERATURE, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthUpper) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper, TEXT_TEMPERATURE_WIDTH_UPPER, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthLower) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower, TEXT_TEMPERATURE_WIDTH_LOWER, alloc, jsonValue);

        return true;
    }

    /************************************************
     * 函数名   : saveBinarySpectrumData
     * 输入参数 :
       QDataStream& out: 输出流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存二进制图谱数据段
     ************************************************/
    bool InfraredSpectrum::saveBinarySpectrumData(QDataStream& out)
    {
        out.device()->seek(SPECTRUM_BASE_LENGTH);

        if(infraredTemperatureDataCount() > 0)
        {
            DataSpecificationUtils::saveBinaryPointerData(out, storageDataType(), m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData.data(), infraredTemperatureDataCount());
        }

        if(visibleLightPhotoDataCount() > 0)
        {
            DataSpecificationUtils::saveBinaryPointerData(out, storageDataType(), m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData.data(), visibleLightPhotoDataCount());
        }

        if(infraredPhotoDataCount() > 0)
        {
            DataSpecificationUtils::saveBinaryPointerData(out, storageDataType(), m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData.data(), infraredPhotoDataCount());
        }

        return true;
    }

    /************************************************
     * 函数名   : saveXMLSpectrumData
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
       QDomElement& element: dom元素
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存XML图谱数据段
     ************************************************/
    bool InfraredSpectrum::saveXMLSpectrumData(XMLDocument& xmlDocumentObj, QDomElement& element)
    {
        xmlDocumentObj.beginElement(element);
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_DATA);

        if (!m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bSkipInfraredTemperatureData)
        {
            QString strData = m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData.toBase64();
            xmlDocumentObj.setValue(TEXT_INFRARED_TEMPERATURE_DATA, strData);
        }

        if (!m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bSkipVisibleLightPhotoData)
        {
            QString strData = m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData.toBase64();
            xmlDocumentObj.setValue(TEXT_VISIBLE_LIGHT_PHOTO_DATA, strData);
        }

        if (!m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bSkipInfraredPhotoData)
        {
            QString strData = m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData.toBase64();
            xmlDocumentObj.setValue(TEXT_INFRARED_PHOTO_DATA, strData);
        }

        return true;
    }

    /************************************************
     * 函数名   : saveJSONSpectrumData
     * 输入参数 :
       rapidjson::Document::AllocatorType& alloc:
       rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 保存JSON图谱数据段
     ************************************************/
    bool InfraredSpectrum::saveJSONSpectrumData(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& jsonValue)
    {
        if (!m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bSkipInfraredTemperatureData) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData, TEXT_INFRARED_TEMPERATURE_DATA, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bSkipVisibleLightPhotoData) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData, TEXT_VISIBLE_LIGHT_PHOTO_DATA, alloc, jsonValue);
        if (!m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bSkipInfraredPhotoData) saveJSONField(m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData, TEXT_INFRARED_PHOTO_DATA, alloc, jsonValue);
        return true;
    }

    /************************************************
     * 函数名   : parseBinarySpectrumExtInfo
     * 输入参数 :
       QDataStream& in: 输入流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析二进制可扩展信息段
     ************************************************/
    bool InfraredSpectrum::parseBinarySpectrumExtInfo(QDataStream& in)
    {
        if (!in.device()->seek(SPECTRUM_HEADER_LENGTH))
        {
            qDebug() << "InfraredSpectrum::parseBinarySpectrumExtInfo failed";
            return false;
        }

        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureUnit, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureUnit);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeWidth, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTempLatticeWidth);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTempLatticeHeight, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTempLatticeHeight);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipVisibleLightLenL1, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasVisibleLightLenL1);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipInfraredDataLenL2, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasInfraredDataLenL2);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipEmissivity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasEmissivity);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipMeasureDistance, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasMeasureDistance);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipAtomTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasAtomTemperature);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipRelativeHumidity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasRelativeHumidity);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipReflectedTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasReflectedTemperature);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthUpper, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureWidthUpper);
        parseBinaryField(in, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bSkipTemperatureWidthLower, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureWidthLower);

        return in.status() == QDataStream::Ok;
    }

    /************************************************
     * 函数名   : parseXMLSpectrumExtInfo
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析XML可扩展信息段
     ************************************************/
    bool InfraredSpectrum::parseXMLSpectrumExtInfo(XMLDocument& xmlDocumentObj)
    {
        xmlDocumentObj.beginElement(spectrumName());
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_EXTINFORMATION);

        parseXMLField(xmlDocumentObj, TEXT_TEMPERATURE_UNIT, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureUnit);
        parseXMLField(xmlDocumentObj, TEXT_TEMPERATURE_LATTICE_WIDTH, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTempLatticeWidth);
        parseXMLField(xmlDocumentObj, TEXT_TEMPERATURE_LATTICE_HEIGHT, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTempLatticeHeight);
        parseXMLField(xmlDocumentObj, TEXT_VISIBLE_LIGHT_PHOTO_DATA_LENGTH_L1, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasVisibleLightLenL1);
        parseXMLField(xmlDocumentObj, TEXT_INFRARED_PHOTO_DATA_LENGTH_L2, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasInfraredDataLenL2);
        parseXMLField(xmlDocumentObj, TEXT_EMISSIVITY, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasEmissivity);
        parseXMLField(xmlDocumentObj, TEXT_MEASURE_DISTANCE, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasMeasureDistance);
        parseXMLField(xmlDocumentObj, TEXT_ATMOSPHERIC_TEMPERATURE, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasAtomTemperature);
        parseXMLField(xmlDocumentObj, TEXT_RELATIVE_HUMIDITY, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasRelativeHumidity);
        parseXMLField(xmlDocumentObj, TEXT_REFLECTED_TEMPERATURE, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasReflectedTemperature);
        parseXMLField(xmlDocumentObj, TEXT_TEMPERATURE_WIDTH_UPPER, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureWidthUpper);
        parseXMLField(xmlDocumentObj, TEXT_TEMPERATURE_WIDTH_LOWER, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureWidthLower);

        xmlDocumentObj.endElement();
        xmlDocumentObj.endElement();

        return true;
    }

    /************************************************
     * 函数名   : parseJSONSpectrumExtInfo
     * 输入参数 :
       const rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析JSON可扩展信息段
     ************************************************/
    bool InfraredSpectrum::parseJSONSpectrumExtInfo(const rapidjson::Value& jsonValue)
    {
        parseJSONField(jsonValue, TEXT_TEMPERATURE_UNIT, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.ucTemperatureUnit, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureUnit);
        parseJSONField(jsonValue, TEXT_TEMPERATURE_LATTICE_WIDTH, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTempLatticeWidth);
        parseJSONField(jsonValue, TEXT_TEMPERATURE_LATTICE_HEIGHT, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTempLatticeHeight);
        parseJSONField(jsonValue, TEXT_VISIBLE_LIGHT_PHOTO_DATA_LENGTH_L1, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasVisibleLightLenL1);
        parseJSONField(jsonValue, TEXT_INFRARED_PHOTO_DATA_LENGTH_L2, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasInfraredDataLenL2);
        parseJSONField(jsonValue, TEXT_EMISSIVITY, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fEmissivity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasEmissivity);
        parseJSONField(jsonValue, TEXT_MEASURE_DISTANCE, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fMeasureDistance, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasMeasureDistance);
        parseJSONField(jsonValue, TEXT_ATMOSPHERIC_TEMPERATURE, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fAtomTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasAtomTemperature);
        parseJSONField(jsonValue, TEXT_RELATIVE_HUMIDITY, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.cRelativeHumidity, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasRelativeHumidity);
        parseJSONField(jsonValue, TEXT_REFLECTED_TEMPERATURE, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fReflectedTemperature, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasReflectedTemperature);
        parseJSONField(jsonValue, TEXT_TEMPERATURE_WIDTH_UPPER, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthUpper, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureWidthUpper);
        parseJSONField(jsonValue, TEXT_TEMPERATURE_WIDTH_LOWER, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.fTemperatureWidthLower, m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.bHasTemperatureWidthLower);

        return true;
    }

    /************************************************
     * 函数名   : parseBinarySpectrumData
     * 输入参数 :
       QDataStream& in: 输入流
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析二进制图谱数据段
     ************************************************/
    bool InfraredSpectrum::parseBinarySpectrumData(QDataStream& in)
    {
        if (!in.device()->seek(SPECTRUM_BASE_LENGTH))
        {
            qDebug() << "InfraredSpectrum::parseBinarySpectrumData failed";
            return false;
        }

        // 红外温度数据
        DataSpecificationUtils::parseBinaryPointerData(in, storageDataType(), m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData, infraredTemperatureDataCount());

        // 可见光照片数据
        DataSpecificationUtils::parseBinaryPointerData(in, storageDataType(), m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData, visibleLightPhotoDataCount());

        // 红外照片数据
        DataSpecificationUtils::parseBinaryPointerData(in, storageDataType(), m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData, infraredPhotoDataCount());

        return in.status() == QDataStream::Ok;
    }

    /************************************************
     * 函数名   : parseXMLSpectrumData
     * 输入参数 :
       XMLDocument& xmlDocumentObj: xml文档对象
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析XML图谱数据段
     ************************************************/
    bool InfraredSpectrum::parseXMLSpectrumData(XMLDocument& xmlDocumentObj)
    {
        xmlDocumentObj.beginElement(spectrumName());
        xmlDocumentObj.beginElement(STR_SPECTRUM_NODE_DATA); 

        m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData = QByteArray::fromBase64(xmlDocumentObj.value(TEXT_INFRARED_TEMPERATURE_DATA).toLatin1());
        m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData = QByteArray::fromBase64(xmlDocumentObj.value(TEXT_VISIBLE_LIGHT_PHOTO_DATA).toLatin1());
        m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData = QByteArray::fromBase64(xmlDocumentObj.value(TEXT_INFRARED_PHOTO_DATA).toLatin1());

        xmlDocumentObj.endElement();
        xmlDocumentObj.endElement();

        return true;
    }

    /************************************************
     * 函数名   : parseJSONSpectrumData
     * 输入参数 :
       const rapidjson::Value& jsonValue: json数据
     * 输出参数 : NULL
     * 返回值   : bool
     * 功能     : 解析JSON图谱数据段
     ************************************************/
    bool InfraredSpectrum::parseJSONSpectrumData(const rapidjson::Value& jsonValue)
    {
        parseJSONField(jsonValue, TEXT_INFRARED_TEMPERATURE_DATA, m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredTemperatureData, m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bHasInfraredTemperatureData);
        parseJSONField(jsonValue, TEXT_VISIBLE_LIGHT_PHOTO_DATA, m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaVisibleLightPhotoData, m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bHasVisibleLightPhotoData);
        parseJSONField(jsonValue, TEXT_INFRARED_PHOTO_DATA, m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.qbaInfraredPhotoData, m_pInfraredSpectrumPrivate->m_stInfraredDataPrivate.bHasInfraredPhotoData);

        return true;
    }

    int InfraredSpectrum::infraredTemperatureDataCount()
    {
        return m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeWidth * m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iTempLatticeHeight;
    }

    int InfraredSpectrum::visibleLightPhotoDataCount()
    {
        return m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iVisibleLightLenL1;
    }

    int InfraredSpectrum::infraredPhotoDataCount()
    {
        return m_pInfraredSpectrumPrivate->m_stInfraredExtInformationPrivate.iInfraredDataLenL2;
    }

}
